<?php
if (!isset($website) ) { header('HTTP/1.1 404 Not Found'); die; }
$errors = "";

	function querytransform($query)
	{
		$var;
		while( $row = mysql_fetch_row($query) )
		{
			$uid = $row[0];
			$name = $row[1];
			$value = $row[2];

			$v = explode("\\",$name);
			if ( $v[0] == "auth" && ($v[1] == "admin" || $v[1] == "operator" ) )
			{
				$channel = isset( $v[2] ) ? $v[2] : "SERVER";
				$rank = $v[1];

				if( !isset( $var[$uid][$rank] ) )
				{
					$var[$uid][$rank] = "";
				}
				else
				{
					$var[$uid][$rank] .= "<br/>";
				}
				$var[$uid][$rank] .= $channel;
			}
			else
			{
				$var[$uid][$name] = $value;
			}
		}
		return $var;
	}

$sql =
"SELECT uid,name,value FROM (SELECT DISTINCT uid as id
FROM `pvpgn_BNET`
WHERE (`value` = 'true' AND (`name` LIKE 'auth_admin%' OR `name` LIKE 'auth_operator%')) OR (`name` = 'auth\\\\command_groups' AND uid <> 0)
ORDER BY uid) AS auth LEFT JOIN `pvpgn_BNET` AS bnet on bnet.uid = auth.id
WHERE `name` = 'acct\\\\username' OR `name` = 'acct\\\\userid' OR
`name` = 'auth\\\\command_groups' OR
((`name` LIKE 'auth_operator%' OR `name` LIKE 'auth_admin%') AND `value` = 'true')
ORDER BY uid,name";

	$result = $db->query("$sql");
	$var = querytransform($result);
?>

<div align="center">
	<table>
		<tr>
			<th class="padLeft" width ="50">ID</th>
			<th>Nick</th>
			<th width ="220">Administrador</th>
			<th width ="220">Operador</th>
			<th width ="50">CG</th>
		</tr>
		<?php
		foreach($var as $v)
		{
			$id = $v['acct\\userid'];
			$name = $v['acct\\username'];
			$admin = $v['admin'];
			$op = $v['operator'];
			$cg = $v['auth\\command_groups'];
		?>
		<tr class="row">
			<td class="padLeft font12"><?=$id?></td>
			<td class="font12"><?=$name?></td>
			<td class="font12"><?=$admin?></td>
			<td class="font12"><?=$op?></td>
			<td class="font12"><i><?=$cg?></i></td>
		</tr>
		<?php 
		}
		$db->free($result);
		?>
	</table>
</div>